package com.bbcare.mqservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bbcare.mqservice.entity.Ipconfig;
import com.bbcare.mqservice.mapper.IpconfigMapper;
import com.bbcare.mqservice.service.IIpconfigService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author gxl
 * @since 2020-03-26
 */
@Service
public class IpconfigServiceImpl extends ServiceImpl<IpconfigMapper, Ipconfig> implements IIpconfigService {

    @Autowired
    private IIpconfigService ipconfigService;
    private static Map<String,Object> map = new HashMap();
    public String getIpByDeptId(String deptId){
        if(!map.containsKey(deptId)){
            List<Ipconfig> list  = ipconfigService.list(new QueryWrapper<Ipconfig>().eq("state",1));
            for (Ipconfig item:list) {
                map.put(item.getDeptId(),item.getIp());
            }
        }

        if(!map.containsKey(deptId)){
            return null;
        }else {
            return map.get(deptId).toString();
        }
    }

}
